'************************************************************************************
' Copyright © 2003-2005 Kathleen Dollard
'
' This software is provided 'as-is', without any express or implied warranty. In no 
' event will the author be held liable for any damages arising from the use of this
' software.
' 
' You may use this software for any purpose, including commercial applications, 
' and you may redistribute this software as part of application delivery: however, 
' this copyright notice may not be removed and you may not otherwise redistribute 
' this software directly other than providing a link to wwww.gendotnet.com. 
'
' You may alter this software to better server your needs (I'd like to hear about your 
' changes in order to make the software better). If you alter the softwre, you must  
' clearly mark it as altered and must not be misrepresented as the original software.
' nor wholly your original work.
'*************************************************************************************
Option Strict On
Option Explicit On 

Imports System
Imports KADGen.MetadataWrapper
Imports KADGen.MetadataAdapter
Imports GenDotNet.MorphMetadata
Imports System.Collections.Generic
Imports KADGen.Utility2005

Namespace KADGen.CodeGenerationSupport
   Public Class MorphMetadata2006

#Region "Public properties and methods"
      Public Sub Run( _
                     ByVal node As Xml.XmlNode, _
                     ByVal runUtility As RunUtility, _
                     ByVal directiveStatus As IStatusDirective)
         Dim morphMetadata As CodeGenerationSupport.IMorphMetadata2006Directive = _
                       CType(node, CodeGenerationSupport.IMorphMetadata2006Directive)
         Dim outputFileName As String = morphMetadata.SinglePass.OutputFile
         ' We could add a check box for the map, but the extra stuff like function replacements always needed?
         Dim sections As KADGen.Utility2005.MorphSections = MorphSections.OrmMap
         If morphMetadata.IncludeAssembly Then
            sections = sections Or MorphSections.Assembly
         End If
         If morphMetadata.IncludeBuildForSP Then
            sections = sections Or MorphSections.Build
         End If
         If morphMetadata.IncludeDataStructure Then
            sections = sections Or MorphSections.DataStructure
         End If

         Dim args As New MorphMetadata2006Args(sections, morphMetadata.ObjectsFromSProcs, _
                  morphMetadata.ObjectsFromTables, morphMetadata.ObjectsFromViews, _
                  morphMetadata.InputFileName, morphMetadata.ORMFileName, morphMetadata.UseSchemaInWhereClause, _
                  morphMetadata.UnbackedColumns)
         runUtility.OutputWithRule(directiveStatus, outputFileName, _
                  morphMetadata.OutputRule, AddressOf Me.Morph, args)


      End Sub

      Public Function Morph(ByVal args As RunArgs) As IO.Stream
         Dim morphArgs As MorphMetadata2006Args = CType(args, MorphMetadata2006Args)
         Try
            Return GenDotNet.MorphMetadata.Utility.Morph( _
                     morphArgs.Sections, _
                     morphArgs.SPOrder.ToString(), _
                     morphArgs.TableOrder.ToString(), _
                     morphArgs.ViewOrder.ToString(), _
                     morphArgs.DataStructureFileName, _
                     morphArgs.OrmMapFileName, _
                     morphArgs.UseSchemaInWhereClause, _
                     morphArgs.UnbackedColumnBehavior)
         Catch ex As Exception
            Throw
         End Try
      End Function
#End Region
   End Class
End Namespace